/*
 * This class is responsible to give the classes with 
 * the time of Application start and the current time
 */
package insulinpumpsimulation.com.his.tasks;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author Arun & Sabahul
 */
public class DurationCalculator {

    private static String starttime = "";
    
    //returns the number of seconds since Jan 1 1970
    private static double startSecond = new Date().getTime() / 1000;
    
    //one instance to prevent change in start time   
    private static DurationCalculator singleton = new DurationCalculator();

    private DurationCalculator() {
//        long startSecond = new Date().getTime() / 1000;
        starttime = getCurrentTime();
    }
    /* Static 'instance' method */

    public static DurationCalculator getInstance() {
        return singleton;
    }

    //Get Current system Time    
    public static String getCurrentTime() {
//        double seconds = new Date().getTime() / 1000;
        int second, minute, hour;
        GregorianCalendar date = new GregorianCalendar();
        second = date.get(Calendar.SECOND);
        minute = date.get(Calendar.MINUTE);
        hour = date.get(Calendar.HOUR_OF_DAY);
        return (hour + ":" + minute + ":" + second+" Hrs.");
    }
    
    // Set Start time of the system the moment system is started
    public static String getStartTime() {
        return starttime;
    }
    // Set Start time of the system the moment system is started
    public static double getStartTimeinSeconds() {
        return startSecond;
    }
    
    
    // Get current time in seconds since unix clock is running since Jan 1 1970
    public static double getCurrentTimeinSeconds() {
        return new Date().getTime() / 1000;
    }
    public static double getRunningDuration(){
        double currentSeconds = new Date().getTime() / 1000;
        
        double durationInSeconds = currentSeconds - startSecond;
        
        return durationInSeconds;
    }
}
